/**
 * @author yxl 余秀良
 * @version 1.0
 * @description: 创建提示框
 * @date 2017年11月23日 下午3:45
 * @address: 四川成都
 * @param options 配置
 * 用法：alert(msg);
 *alert({content: msg, ok:function () {},cancel:function () {}});
 *alert({content: msg, ok:function () {}});
 */

//eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p;}('m.i(\'<u t="s" p="../o/7/l/7.a.n.l">\');m.i(\'<f r="../o/7/7.a.n.q"></f>\');2 a(0){1(4(0)===\'h\'&&0.k===j){5.3=0}e{5.3=0.3}1(4(0)===\'h\'&&0.k===j){c({b:5.3})}1(4(0.9)==="2"&&4(0.8)!=="2"){c({b:5.3}).g(2(6){1(6.d){0.9()}})}1(4(0.9)==="2"&&4(0.8)==="2"){c({b:5.3,E:\'D\',C:H,G:\'#F\',B:\'#x\',w:\'v\',A:"z"}).g(2(6){1(6.d){0.9()}e 1(6.y===\'8\'){0.8()}})}}',44,44,'options|if|function|content|typeof|this|result|jquery|cancel|ok|alert|title|swal|value|else|script|then|string|writeln|String|constructor|css|document|min|framwork|href|js|src|stylesheet|rel|link|确定|confirmButtonText|d33|dismiss|取消|cancelButtonText|cancelButtonColor|showCancelButton|warning|type|3085d6|confirmButtonColor|true'.split('|'),0,{}));
/**
 * @author yxl 余秀良
 * @version 1.0
 * @description: 创建提示框
 * @date 2017年11月23日 下午3:45
 * @address: 四川成都
 * @param options 配置
 * 用法：alert(msg);
 *alert({content: msg, ok:function () {},cancel:function () {}});
 *alert({content: msg, ok:function () {}});
 */
function alert(options) {
    if (typeof(options) === 'string' && options.constructor === String) {
        this.content = options;
    } else {
        this.content = options.content;
    }
    this.title = options.title || "提示";
    this.type = options.type || 0;//类型
    var okId = Math.floor(Math.random() * 100) + "_ok_btn";
    var cancelId = Math.floor(Math.random() * 1000) + "_cancel_btn";
    var m = $("#modal");
    if (m !== undefined) {
        hideModal(m);
    }
    if (typeof(options.cancel) !== "function") {
        this.display = 'display:none;';
        this.okBtnMargin = 'margin-right: 40%;';
    } else {
        this.okBtnMargin = 'margin-right: 10%;';
    }
    //提示模态框
    var view = '<div id="modal" style="z-index:9999999;" class="modal fade" data-backdrop="static" data-keyboard="false" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel"><div id="dialog" class="modal-dialog" role="document" style="width: 400px;margin-top: 10%;"> <div class="modal-content"> <div class="modal-header"> <button style="visibility: hidden" type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <h4 class="modal-title text-center" id="gridSystemModalLabel">提示</h4> </div> <div id="content" class="modal-body text-center"> </div> <div class="modal-footer text-left"> <button type="button" class="btn btn-primary" id="' + okId + '" style="' + this.okBtnMargin + '">确定 </button> <button type="button" class="btn btn-default"  id="' + cancelId + '" style="' + this.display + ';margin-right: 25%">取消</button> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal -->';
    $('body').append(view);
    var title_div = $("#gridSystemModalLabel");
    var content_div = $("#content");
    var okBtn = $("#" + okId);
    var cancelBtn = $("#" + cancelId);
    switch (this.type) {
        case 0:
            title_div.html('<span style="font-size: 20px;color: #6c3;" class="glyphicon glyphicon-ok" aria-hidden="true">' + this.title + '</span>');
            content_div.html('<span style="font-size: 25px;" >' + this.content + '</span>');
            okBtn.css({
                backgroundColor: "#6c3",
                borderColor: "#6c3"
            });
            break;
        case 1:
            title_div.html('<span style="font-size: 20px;color: red" class="glyphicon glyphicon-remove" aria-hidden="true">错误' + this.title + '</span>');
            content_div.html('<span style="font-size: 25px;color: red" >' + this.content + '</span>');
            okBtn.css({
                backgroundColor: "red",
                borderColor: "red"
            });
            break;
        case 2:
            title_div.html('<span style="font-size: 20px;color: #f39c12" class="glyphicon glyphicon-warning-sign" aria-hidden="true">警告' + this.title + '</span>');
            content_div.html('<span style="font-size: 25px;" >' + this.content + '</span>');
            okBtn.css({
                backgroundColor: "#f39c12",
                borderColor: "#f39c12"
            });
            break;
        default:
            title_div.html('<span style="font-size: 20px;color: green;" class="glyphicon glyphicon-ok" aria-hidden="true">' + this.title + '</span>');
            content_div.html('<span style="font-size: 25px;" >' + this.content + '</span>');
            okBtn.css({
                backgroundColor: "#6c3",
                borderColor: "#6c3"
            });
            break;
    }
    var modal = $("#modal");
    modal.modal("show");
    okBtn.bind("click", function () {
        if (typeof(options.ok) === "function") {
            options.ok();
        }
        hideModal(modal);
    });
    cancelBtn.bind("click", function () {
        if (typeof(options.cancel) === "function") {
            options.cancel();
        }
        hideModal(modal);
    });

    function hideModal(modal) {
        modal.modal("hide");
        $(".modal-backdrop").remove();
        var body = $("body");
        body.css("min-width", "");
        body.css("padding-right", "");
        body.removeClass('modal-open');
        modal.remove();
    }
}